package com.project.lk.nurseapp.login;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;

import com.jcodecraeer.xrecyclerview.SimpleViewSwitcher;
import com.project.lk.nurseapp.R;
import com.project.lk.nurseapp.base.BaseActivity;
import com.project.lk.nurseapp.base.UrlContants;
import com.project.lk.nurseapp.login.presenter.IRegisterView;
import com.project.lk.nurseapp.login.presenter.RegisterPresenter;
import com.project.lk.nurseapp.utils.AppManager;
import com.project.lk.nurseapp.utils.ProgressUtils;
import com.project.lk.nurseapp.utils.ToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
/**
 * 功能介绍：
 * 项目名：
 * 模块名称：
 * 作者：LK
 * 日期：2018/1/9
 * 修改日期：
 */
public class RegisterActivity extends AppCompatActivity implements IRegisterView{


    @BindView(R.id.login_user)
    EditText loginUser;
    @BindView(R.id.code_edit)
    EditText codeEdit;
    @BindView(R.id.login_psw)
    EditText loginPsw;
    @BindView(R.id.register_but)
    Button registerBut;
    private Unbinder mBind;
    @BindView(R.id.mProgressBar)
    SimpleViewSwitcher mProgressBar;
    private RegisterPresenter presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(getLayoutId());
        //设置全屏
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//                WindowManager.LayoutParams.FLAG_FULLSCREEN);
//        getWindow().addFlags(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        getWindow().addFlags(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        AppManager.getAppManager().addActivity(this);
        //绑定黄油刀
        mBind = ButterKnife.bind(this);
        init();

    }

    private void init() {
        initData();
        initView();
    }

    protected void initData() {
        presenter = new RegisterPresenter(this);
    }

    protected void initView() {
        ProgressUtils.setProgress(mProgressBar);
    }

    protected int getLayoutId() {
        return R.layout.activity_register;
    }


    @OnClick({R.id.back, R.id.send_code, R.id.register_but})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                AppManager.getAppManager().finishActivity();
                break;
            case R.id.send_code:
                if (!TextUtils.isEmpty(loginUser.getText())){
                    presenter.getCode(UrlContants.GET_CODE_URL,loginUser.getText().toString());
                }else {
                    ToastUtils.showShortToast("请填写手机号");
                }
                break;
            case R.id.register_but:
                if (TextUtils.isEmpty(loginUser.getText())){
                    ToastUtils.showShortToast("手机号不能为空");
                }else if (TextUtils.isEmpty(codeEdit.getText())){
                    ToastUtils.showShortToast("验证码不能为空");
                }else if (TextUtils.isEmpty(loginPsw.getText())){
                    ToastUtils.showShortToast("密码不能为空");
                }else {
                    presenter.register(UrlContants.REGISTER_URL,loginUser.getText().toString(),
                            loginPsw.getText().toString(),codeEdit.getText().toString());
                    mProgressBar.setVisibility(View.VISIBLE);
                }

                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mBind != null) {
            mBind.unbind();
        }
    }

    @Override
    public void registerSuccess() {

        mProgressBar.setVisibility(View.GONE);
    }

    @Override
    public void registerFail() {
        mProgressBar.setVisibility(View.GONE);
    }

    @Override
    public void codeSuccess() {

    }

    @Override
    public void codeFail() {

    }
}
